<template>
	<view class="content">
		<nav-bar @cutClick="cutClick" bgColor="#FFE8CA" :leftText="$store.getters.getKeMuName"></nav-bar>
		<question @accuracy="accuracy" ref="question" type="1"></question>
		<advertising v-if="banner.length>0" @bannerClick="bannerClick" :banner="banner"></advertising>
	</view>
</template>

<script>
	import advertising from '@/components/advertising.vue'
	import question from '@/components/question.vue'
	import {banner} from "@/api/index.js"
	export default {
		components: {
			advertising,
			question,
		},
		data() {
			return {
				banner: [],
			}
		},
		computed: {
			loginInfo() {
				return this.$store.state.loginInfo;
			},
		},
		onLoad() {
		},
		mounted() {
		},
		onShow() {
			if(this.$common.isEmpty(this.loginInfo)){
				uni.showToast({
					title: '请先绑定手机号',
					icon: 'none'
				})
				uni.switchTab({
					url: '/pages/index/index'
				})
				return
			}
			this.getBanner();
			setTimeout(()=>{
				this.$refs.question.getPracticeInfoByChar('2')
			},200)
		},
		methods: {
			bannerClick(){
				const item=this.banner[0];
				if(item.type==1){//web链接
					uni.navigateTo({
						url: '/pagesD/webView/index?url='+encodeURIComponent(item.url)
					})
				}else if(item.type==2){//小程序地址
					// #ifdef MP-WEIXIN
					wx.navigateToMiniProgram({
						appId: 'wx911aceb2827f8f8c',
						shortLink: item.url,
						// envVersion: 'develop',//develop开发版  trial体验版  release正式版
					})
					// #endif
					// #ifndef MP-WEIXIN
					uni.showToast({title: '暂不支持',icon: 'error'})
					// #endif
				}
			},
			getBanner(){
				banner().then(res=>{
					this.banner=res.data.filter(item=>item.show=='2');
				})
			},
			accuracy(tabIndex,index,cindex,item,citem){
				this.$store.dispatch('getSubjectByDept');
				this.$store.commit('set',['exerciseList',[]]);
				this.$store.commit('set',['isError',false]);
				uni.navigateTo({
					url: `/pagesC/topicRelated/answerSheet?type=1&title=${item.n}&subtitle=${citem.n}&isOldValue=1`
				})
			},
			cutClick(){
				uni.navigateTo({
					url: `/pages/cutDrawer/index`
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	page{
		background-color: #F8F8F8;
	}
	.content{
		min-height: 100vh;
		font-size: 28rpx;
		background-color: #fff;
	}
</style>
